# 方法一字符串反转
class Solution:
    def reverse(self, x: int) -> int:
        if x == 0:
            return 0
        y = x if x > 0 else -x
        s = str(y)
        n = len(s)
        res = [None] * n
        for i in range(n):
            res[n - 1 -i] = s[i]
        if x > 0:
            res = int(''.join(res))
        else:
            res = -int(''.join(res))
        if res > 2147483647 or res < -2147483647:
            return 0
        else:
            return res